package com.hoyin.lightctrl_esp8266;

import android.util.Log;

import java.io.OutputStream;
import java.net.Socket;

public class SocketSendThread extends Thread {
	private OutputStream mOutStream;
	private String data;

	public SocketSendThread(OutputStream outputStream) {
		mOutStream = outputStream;
	}

	public void storeMsg(String msg){
		data = msg;
	}

	private void writeMsg(String msg){
		if(msg.length() == 0 || mOutStream == null)
			return;
		try {   //发送
			Log.i("HHH", "I don't know, try it");
			mOutStream.write(msg.getBytes());
			mOutStream.flush();
		}catch (Exception e) {
			Log.i("HHH", "Gan!");
			Log.i("HHH", String.valueOf(e));
			e.printStackTrace();
		}
	}

	public void run(){
		writeMsg(data);
	}
}
